package com.xiaolin.util;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * @ClassName TestListIterator
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/9/27
 * @Version 1.0
 */
public class TestListIterator {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        ListIterator<Integer> listIterator = list.listIterator();
        //从起始位置向后遍历
        while (listIterator.hasNext()){
            System.out.println(listIterator.next());
        }
        //从末尾向前遍历
        while (listIterator.hasPrevious()){
            System.out.println(listIterator.previous());
        }
    }
}


